﻿/*********************************************
 创建者：  dmhai
 创建时间：2017-05-08
 功能说明：店铺最低深度导入导出
 ********************************************/

using com.nm.library.Excels;
using System;
using System.Collections.Generic;
using System.ComponentModel.Composition;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
using com.nm;
using com.nm.library.Helper;
using DistributeAPI;
using DistributeAPI.Model;

namespace PlanAPI.Export
{
    [Export(typeof(ExcelImport))]
    class DCBasModelMinQty : ExcelImport
    {
        public override ExcelImportType Type => ExcelImportType.DCBASMODELMINQTY;
        public override Dictionary<string, ImportVerify> DictFields => _dictFields;

        private Dictionary<string, ImportVerify> _dictFields = new List<ImportVerify> { 
            new ImportVerify{ ColumnName="店铺编号",FieldName="ShopCode",DataType=typeof(string),VerifyFunc =(e,extra)=> ExcelImportHelper.GetCellMsg(e.CellValue,e.ColName,100,true,true)},
            new ImportVerify{ ColumnName="店铺名称",FieldName="ShopName",DataType=typeof(string),VerifyFunc =(e,extra)=> ExcelImportHelper.GetCellMsg(e.CellValue,e.ColName,100,false,true)},
            new ImportVerify{ ColumnName="类别名称",FieldName="KindName",DataType=typeof(string),VerifyFunc =(e,extra)=> ExcelImportHelper.GetCellMsg(e.CellValue,e.ColName,100,true,true)},
            new ImportVerify{ ColumnName="品类名称",FieldName="ModelName",DataType=typeof(string),VerifyFunc =(e,extra)=> ExcelImportHelper.GetCellMsg(e.CellValue,e.ColName,100,true,true)},
            new ImportVerify{ ColumnName="小品类名称",FieldName="ItemName",DataType=typeof(string),VerifyFunc =(e,extra)=> ExcelImportHelper.GetCellMsg(e.CellValue,e.ColName,100,true,true)},
            new ImportVerify{ ColumnName="尺码类型",FieldName="SizeTypeFlag",DataType=typeof(string),VerifyFunc =(e,extra)=> ExcelImportHelper.GetCellMsg(e.CellValue,e.ColName,100,true,true)},
            new ImportVerify{ ColumnName="尺码名称",FieldName="SizeName",DataType=typeof(string),VerifyFunc =(e,extra)=> ExcelImportHelper.GetCellMsg(e.CellValue,e.ColName,100,true,true)},
            new ImportVerify{ ColumnName="尺码长度",FieldName="SizeLength",DataType=typeof(string),VerifyFunc =(e,extra)=> ExcelImportHelper.GetCellMsg(e.CellValue,e.ColName,100,true,true)},
            new ImportVerify{ ColumnName="首配深度",FieldName="FirstDCQty",DataType=typeof(decimal),VerifyFunc =(e,extra)=> ExcelImportHelper.GetCellMsg(e.CellValue,e.ColName,100,false,true)},
            new ImportVerify{ ColumnName="最低深度",FieldName="MinQty",DataType=typeof(decimal),VerifyFunc =(e,extra)=> ExcelImportHelper.GetCellMsg(e.CellValue,e.ColName,100,false,true)}

        }.ToDictionary(e => e.ColumnName, e => e);

        public override object SaveImportData(DataTable dt, Dictionary<string, object> extraInfo, int userId)
        {
            var index = dt.Rows.Count;
            var msg = $"成功导入{index}条数据";
            var result = new ImportResult
            {
                IsSuccess = true,
                ExtraInfo = "导入成功",
                Message = msg
            };
            try
            {
                var list = ModelConvertHelper<DCBasModelMinQtyModel.ImportExcelModel>.ConvertToModel(dt);
                var handler = new DCBasModelMinQtyHandler();
                handler.ImportExcel(list);
            }
            catch (Exception ex)
            {
                Log.Error("导入店铺深度表：" + ex);
                result.IsSuccess = false;
                result.ExtraInfo = ex;
                result.Message = ex.Message;
            }
            return result;
        }

        public override DataTable GetExportData(string Keys)
        {
            throw new NotImplementedException();
        }
    }
}
